package com.yuanian.ecsplus.template.adapter;

import com.yuanian.ecsplus.cache.CacheManager;
import com.yuanian.ecsplus.meta.entity.MetaEntity;
import com.yuanian.ecsplus.model.entity.BaseModel;
import com.yuanian.ecsplus.model.vo.BaseVoModel;
import com.yuanian.ecsplus.page.PageFilter;
import com.yuanian.ecsplus.page.PageSql;
import com.yuanian.ecsplus.page.Pagination;
import com.yuanian.ecsplus.template.ControllerTemplate;

import java.util.List;
import java.util.Map;

/**
 * ControllerTemplate默认适配器，可覆盖其中的方法，提供弹性扩展
 * @param <T>
 */
public abstract class ControllerAdapter<T extends BaseModel> extends ControllerTemplate<T> {

    @Override
    protected void createBeforeCallback(Map initData, Boolean insertFlag) {

    }

    @Override
    protected void createAfterCallback(T baseVoModel, Boolean insertFlag) {

    }

    @Override
    protected boolean insertBeforeCallback(T baseVoModel) {
        return true;
    }

    @Override
    protected void insertAfterCallback(T baseVoModel) {

    }

    @Override
    protected boolean updateBeforeCallback(T baseVoModel) {
        return true;
    }

    @Override
    protected void updateAfterCallback(T baseVoModel) {

    }

    @Override
    protected boolean deleteBeforeCallback(T baseVoModel) {
        return true;
    }

    @Override
    protected void deleteAfterCallback(T baseVoModel) {

    }

    @Override
    protected boolean issueBeforeCallback(T baseVoModel) {
        return true;
    }

    @Override
    protected void issueAfterCallback(T baseVoModel) {

    }

    @Override
    protected void selectByObjectIdBeforeCallback(String objectId, Boolean viewFlag) {

    }

    @Override
    protected void selectByObjectIdAfterCallback(T baseVoModel, Boolean viewFlag) {

    }

    @Override
    protected void pageFilterSelectListAfterCallback(Pagination<T> fabiaoVoPagination) {

    }

    @Override
    protected String pageFilterSelectListBeforeCallback(Class clz, PageFilter pageFilter) {
        //获取VO对应的APINAME
        String apiName = CacheManager.getInstance().getMetaVo(clz).getMetaClass().getApiName();
        MetaEntity metaEntity = CacheManager.getInstance().getMetaEntity(apiName);
        if (metaEntity == null) {
            return "";
        }
        return metaEntity.getMetaClass().getSql(pageFilter, pageFilter.getContactStr());
    }


    @Override
    protected boolean batchSaveBeforeCallback(List<T> list) {
        return true;
    }

    @Override
    protected void batchSaveAfterCallback(List<T> list) {

    }

    @Override
    protected boolean batchInsertBeforeCallback(List<T> list) {
        return true;
    }

    @Override
    protected void batchInsertAfterCallback(List<T> list) {

    }

    @Override
    protected boolean saveBeforeCallback(T t) {
        return true;
    }

    @Override
    protected void saveAfterCallback(T t) {

    }

    @Override
    protected void pageSelectListBeforeCallback(PageSql pageSql) {

    }

    @Override
    protected void pageSelectListAfterCallback(Pagination<T> invoiceVoPagination) {

    }

    @Override
    protected boolean batchDeleteBeforeCallback(List<T> list) {
        return true;
    }

    @Override
    protected void batchDeleteAfterCallback(List<T> list) {

    }

    @Override
    protected boolean deleteByObjectIdBeforeCallback(String objectId) {
        return true;
    }

    @Override
    protected void deleteByObjectIdAfterCallback(String objectId) {

    }

}
